<script>
	import {
		mapGetters
	} from 'vuex';
	import IMService from '@/lib/imservice';
	import http from '@/apis/http';
	export default {
		computed: {
			...mapGetters({
				userInfo: 'user/info',
				hasLogin: 'user/hasLogin'
			})
		},
		globalData: {
			imService: null,
			postId: null,
			location: {},
			currentLocation: {}, //当前位置信息
		},

		onLaunch: function(o) {
			console.log('App Launch', o);
			
			// 从本地存储恢复登录状态
			http.checkLogin();
			
			//注册聊天
			if (this.hasLogin) {
				console.log('this.goEasy.getConnectionStatus()==' + this.goEasy.getConnectionStatus());
				if (this.goEasy.getConnectionStatus() === 'disconnected') {
					this.globalData.imService = new IMService(this.goEasy, this.GoEasy);
					this.globalData.imService.connect(this.userInfo);
				}
			}
			//#ifdef MP-WEIXIN
			this.verifyUpdate();
			//#endif
			this.$AppEntryController.getWeChatOpenId();
			// #ifdef H5
			this.$AppEntryController.handleH5BrowserAddressBarAuth();
			// #endif
		},
		onShow: function(o) {
			console.log('App Show', o);
		},
		onHide: function() {
			console.log('App Hide');
		},

		methods: {
			verifyUpdate() {
				console.log('verifyUpdate');
				const updateManager = uni.getUpdateManager();
				updateManager.onCheckForUpdate(function(res) {
					// 请求完新版本信息的回调
					console.log('onCheckForUpdate');
					console.log(res.hasUpdate);
					if (res.hasUpdate) {
						updateManager.onUpdateReady(function(res) {
							uni.showModal({
								title: '更新提示',
								content: '新版本已经准备好，是否重启应用？',
								success(res) {
									if (res.confirm) {
										// 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
										updateManager.applyUpdate();
									}
								}
							});
						});

						updateManager.onUpdateFailed(function(res) {
							// 新的版本下载失败
							console.log('onUpdateFailed');
						});
					}
				});
			}
		}
	};
</script>

<style lang="scss">
@import '@/uni_modules/uview-ui/index.scss';
	// 字体图标
	@import './static/yzb/yzb-icon.css';
	// 公共类名
	@import './static/style/commonClass.scss';
	// 模板之前css
	@import './static/style/beforeCommon.css';
</style>